import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import vant from 'vant'
import axios from 'axios'
import { get, post } from './axios/http'
import 'vant/lib/index.css';
import topNav from '@/components/topNav'
import { Toast } from 'vant';
import api from "./axios/api"


// const vConsole = new Vconsole()
Vue.prototype.$axios = axios
Vue.config.productionTip = false,
Vue.use(Toast);
Vue.prototype.$get = get;
Vue.prototype.$post = post;
Vue.prototype.$api = api;
Vue.use(vant)
Vue.component('topNav', topNav)
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')



//路由守卫
router.beforeEach((to, from, next) => {
  if (to.meta.requireAuth) {
    if (JSON.parse(localStorage.getItem("phone"))) {
      next();
    } else {
      next({
        path: "/"//指向为你的登录界面
      });
    }
  } else {
    next();
  }

  if (to.fullPath === "/") {
    if (JSON.parse(localStorage.getItem("phone"))) {
      next({
        path: from.fullPath
      });
    } else {
      next();
    }
  }
});